#ifndef __SPACEMIT_PM853_H__
#define __SPACEMIT_PM853_H__

#define SPACEMIT_PM853_ID_REG		0x0
#define SPACEMIT_PM853_MAX_REG		0xf1

#define SPACEMIT_PM853_ID		0x50

#define PM853_LDO_BUCK_EN_REG0		0x11
#define PM853_LDO_BUCK_EN_REG1		0x12
#define PM853_LDO_BUCK_EN_REG2		0x13
#define PM853_LDO_BUCK_EN_REG3		0x14

#define PM853_BUCK1_EN_MSK		0x1
#define PM853_BUCK2_EN_MSK		0x2
#define PM853_BUCK3_EN_MSK		0x4
#define PM853_BUCK4_EN_MSK		0x8
#define PM853_BUCK5_EN_MSK		0x10

#define PM853_LDO1_EN_MSK		0x20
#define PM853_LDO2_EN_MSK		0x40
#define PM853_LDO3_EN_MSK		0x80
#define PM853_LDO4_EN_MSK		0x1
#define PM853_LDO5_EN_MSK		0x2
#define PM853_LDO6_EN_MSK		0x4
#define PM853_LDO7_EN_MSK		0x8
#define PM853_LDO8_EN_MSK		0x10
#define PM853_LDO9_EN_MSK		0x20
#define PM853_LDO10_EN_MSK		0x40
#define PM853_LDO11_EN_MSK		0x80
#define PM853_LDO12_EN_MSK		0x1
#define PM853_LDO13_EN_MSK		0x2
#define PM853_LDO14_EN_MSK		0x4
#define PM853_LDO15_EN_MSK		0x8
#define PM853_LDO16_EN_MSK		0x10
#define PM853_LDO17_EN_MSK		0x20
#define PM853_LDO18_EN_MSK		0x40
#define PM853_LDO19_EN_MSK		0x80
#define PM853_LDO20_EN_MSK		0x1
#define PM853_LDO21_EN_MSK		0x2
#define PM853_LDO22_EN_MSK		0x4
#define PM853_SW_EN_MSK			0x8


#define PM853_BUCK1_VSEL_REG		0x30
#define PM853_BUCK2_VSEL_REG		0x50
#define PM853_BUCK3_VSEL_REG		0x60
#define PM853_BUCK4_VSEL_REG		0x80
#define PM853_BUCK5_VSEL_REG		0x90

#define PM853_BUCK1_VSEL_MSK		0x7f
#define PM853_BUCK2_VSEL_MSK		0x7f
#define PM853_BUCK3_VSEL_MSK		0x7f
#define PM853_BUCK4_VSEL_MSK		0x7f
#define PM853_BUCK5_VSEL_MSK		0x7f

#define PM853_BUCK1_SVSEL_REG		0x32
#define PM853_BUCK2_SVSEL_REG		0x51
#define PM853_BUCK3_SVSEL_REG		0x61
#define PM853_BUCK4_SVSEL_REG		0x81
#define PM853_BUCK5_SVSEL_REG		0x91

#define PM853_BUCK_SVSEL_MSK		0x7f


#define PM853_LDO_VSEL_MSK		0xf
#define PM853_LDO1_VSEL_REG		0xb1
#define PM853_LDO2_VSEL_REG		0xb4
#define PM853_LDO3_VSEL_REG		0xb7
#define PM853_LDO4_VSEL_REG		0xba
#define PM853_LDO5_VSEL_REG		0xbd
#define PM853_LDO6_VSEL_REG		0xc0
#define PM853_LDO7_VSEL_REG		0xc3
#define PM853_LDO8_VSEL_REG		0xc6
#define PM853_LDO9_VSEL_REG		0xc9
#define PM853_LDO10_VSEL_REG		0xcc
#define PM853_LDO11_VSEL_REG		0xcf
#define PM853_LDO12_VSEL_REG		0xd2
#define PM853_LDO13_VSEL_REG		0xd5
#define PM853_LDO14_VSEL_REG		0xd8
#define PM853_LDO15_VSEL_REG		0xdb
#define PM853_LDO16_VSEL_REG		0xde
#define PM853_LDO17_VSEL_REG		0xe1
#define PM853_LDO18_VSEL_REG		0xe4
#define PM853_LDO19_VSEL_REG		0xe7
#define PM853_LDO20_VSEL_REG		0xea
#define PM853_LDO21_VSEL_REG		0xed
#define PM853_LDO22_VSEL_REG		0xf0

#define PM853_LDO1_SVSEL_REG		0xb0
#define PM853_LDO2_SVSEL_REG		0xb3
#define PM853_LDO3_SVSEL_REG		0xb6
#define PM853_LDO4_SVSEL_REG		0xb9
#define PM853_LDO5_SVSEL_REG		0xbc
#define PM853_LDO6_SVSEL_REG		0xbf
#define PM853_LDO7_SVSEL_REG		0xc2
#define PM853_LDO8_SVSEL_REG		0xc5
#define PM853_LDO9_SVSEL_REG		0xc8
#define PM853_LDO10_SVSEL_REG		0xcb
#define PM853_LDO11_SVSEL_REG		0xce
#define PM853_LDO12_SVSEL_REG		0xd1
#define PM853_LDO13_SVSEL_REG		0xd4
#define PM853_LDO14_SVSEL_REG		0xd7
#define PM853_LDO15_SVSEL_REG		0xda
#define PM853_LDO16_SVSEL_REG		0xdd
#define PM853_LDO17_SVSEL_REG		0xe0
#define PM853_LDO18_SVSEL_REG		0xe3
#define PM853_LDO19_SVSEL_REG		0xe6
#define PM853_LDO20_SVSEL_REG		0xe9
#define PM853_LDO21_SVSEL_REG		0xec
#define PM853_LDO22_SVSEL_REG		0xef

#define PM853_LDO_SVSEL_MSK		0xf

enum PM853_buck_reg {
	PM853_ID_DCDC1,
	PM853_ID_DCDC2,
	PM853_ID_DCDC3,
	PM853_ID_DCDC4,
	PM853_ID_DCDC5,
};

enum PM853_ldo_reg {
	PM853_ID_LDO1,
	PM853_ID_LDO2,
	PM853_ID_LDO3,
	PM853_ID_LDO4,
	PM853_ID_LDO5,
	PM853_ID_LDO6,
	PM853_ID_LDO7,
	PM853_ID_LDO8,
	PM853_ID_LDO9,
	PM853_ID_LDO10,
	PM853_ID_LDO11,
	PM853_ID_LDO12,
	PM853_ID_LDO13,
	PM853_ID_LDO14,
	PM853_ID_LDO15,
	PM853_ID_LDO16,
	PM853_ID_LDO17,
	PM853_ID_LDO18,
	PM853_ID_LDO19,
	PM853_ID_LDO20,
	PM853_ID_LDO21,
	PM853_ID_LDO22,
};

enum PM853_switch_reg {
	PM853_ID_SWITCH1,
};

#define PM853_BUCK_LINER_RANGE1						\
static const struct pm8xx_linear_range pm853_buck_ranges1[] = {		\
        REGULATOR_LINEAR_RANGE(480000, 0x0, 0x50, 10000),		\
        REGULATOR_LINEAR_RANGE(1320000, 0x51, 0x7F, 40000),		\
};

#define PM853_BUCK_LINER_RANGE2						\
static const struct pm8xx_linear_range pm853_buck_ranges2[] = {		\
        REGULATOR_LINEAR_RANGE(600000, 0x0, 0x50, 12500),		\
        REGULATOR_LINEAR_RANGE(1650000, 0x51, 0x7F, 50000),		\
};

#define PM853_LDO_LINER_RANGE1						\
static const struct pm8xx_linear_range pm853_ldo_ranges1[] = {		\
        REGULATOR_LINEAR_RANGE(1200000, 0x0, 0x6, 100000),		\
        REGULATOR_LINEAR_RANGE(1850000, 0x7, 0x8, 50000),		\
        REGULATOR_LINEAR_RANGE(2750000, 0x9, 0xc, 50000),		\
        REGULATOR_LINEAR_RANGE(3000000, 13, 14, 100000),		\
        REGULATOR_LINEAR_RANGE(3300000, 15, 15, 0),		\
};

#define PM853_LDO_LINER_RANGE2						\
static const struct pm8xx_linear_range pm853_ldo_ranges2[] = {		\
        REGULATOR_LINEAR_RANGE(1600000, 0x0, 0x3, 100000),		\
};

#define PM853_LDO_LINER_RANGE3						\
static const struct pm8xx_linear_range pm853_ldo_ranges3[] = {		\
        REGULATOR_LINEAR_RANGE(1200000, 0x0, 0xf, 50000),		\
};

#define PM853_LDO_LINER_RANGE4						\
static const struct pm8xx_linear_range pm853_ldo_ranges4[] = {		\
        REGULATOR_LINEAR_RANGE(1000000, 0x0, 0x7, 50000),		\
};

#define PM853_SWITCH_LINER_RANGE					\
static const struct pm8xx_linear_range pm853_switch_ranges[] = {		\
};

#define PM853_REGULATOR_BUCK_DESC		\
static const struct pm8xx_buck_desc pm853_buck_desc[] = {	\
	/* BUCK */		\
	PM8XX_DESC_COMMON(PM853_ID_DCDC1, "DCDC_REG1",					\
			128, PM853_BUCK1_VSEL_REG, PM853_BUCK1_VSEL_MSK,	\
			PM853_LDO_BUCK_EN_REG0, PM853_BUCK1_EN_MSK,		\
			PM853_BUCK1_SVSEL_REG, PM853_BUCK_SVSEL_MSK,		\
			pm853_buck_ranges1),	\
	\
	PM8XX_DESC_COMMON(PM853_ID_DCDC2, "DCDC_REG2",					\
			128, PM853_BUCK2_VSEL_REG, PM853_BUCK2_VSEL_MSK,	\
			PM853_LDO_BUCK_EN_REG0, PM853_BUCK2_EN_MSK,		\
			PM853_BUCK2_SVSEL_REG, PM853_BUCK_SVSEL_MSK,		\
			pm853_buck_ranges2),	\
	\
	PM8XX_DESC_COMMON(PM853_ID_DCDC3, "DCDC_REG3",					\
			128, PM853_BUCK3_VSEL_REG, PM853_BUCK3_VSEL_MSK,	\
			PM853_LDO_BUCK_EN_REG0, PM853_BUCK3_EN_MSK,		\
			PM853_BUCK3_SVSEL_REG, PM853_BUCK_SVSEL_MSK,		\
			pm853_buck_ranges2),	\
	\
	PM8XX_DESC_COMMON(PM853_ID_DCDC4, "DCDC_REG4",					\
			128, PM853_BUCK4_VSEL_REG, PM853_BUCK4_VSEL_MSK,	\
			PM853_LDO_BUCK_EN_REG0, PM853_BUCK4_EN_MSK,		\
			PM853_BUCK4_SVSEL_REG, PM853_BUCK_SVSEL_MSK,		\
			pm853_buck_ranges1),	\
	\
	PM8XX_DESC_COMMON(PM853_ID_DCDC5, "DCDC_REG5",					\
			128, PM853_BUCK5_VSEL_REG, PM853_BUCK5_VSEL_MSK,	\
			PM853_LDO_BUCK_EN_REG0, PM853_BUCK5_EN_MSK,		\
			PM853_BUCK5_SVSEL_REG, PM853_BUCK_SVSEL_MSK,		\
			pm853_buck_ranges2),	\
};

#define PM853_REGULATOR_LDO_DESC		\
static const struct pm8xx_buck_desc pm853_ldo_desc[] = {	\
	PM8XX_DESC_COMMON(PM853_ID_LDO1, "LDO_REG1",					\
			16, PM853_LDO1_VSEL_REG, PM853_LDO_VSEL_MSK,		\
			PM853_LDO_BUCK_EN_REG0, PM853_LDO1_EN_MSK,		\
			PM853_LDO1_SVSEL_REG, PM853_LDO_SVSEL_MSK,		\
			pm853_ldo_ranges1),					\
	\
	PM8XX_DESC_COMMON(PM853_ID_LDO2, "LDO_REG2",					\
			16, PM853_LDO2_VSEL_REG, PM853_LDO_VSEL_MSK,		\
			PM853_LDO_BUCK_EN_REG0, PM853_LDO2_EN_MSK,		\
			PM853_LDO2_SVSEL_REG, PM853_LDO_SVSEL_MSK,		\
			pm853_ldo_ranges1),					\
	\
	PM8XX_DESC_COMMON(PM853_ID_LDO3, "LDO_REG3",					\
			16, PM853_LDO3_VSEL_REG, PM853_LDO_VSEL_MSK,		\
			PM853_LDO_BUCK_EN_REG0, PM853_LDO3_EN_MSK,		\
			PM853_LDO3_SVSEL_REG, PM853_LDO_SVSEL_MSK,		\
			pm853_ldo_ranges1),					\
	\
	PM8XX_DESC_COMMON(PM853_ID_LDO4, "LDO_REG4",					\
			16, PM853_LDO4_VSEL_REG, PM853_LDO_VSEL_MSK,		\
			PM853_LDO_BUCK_EN_REG1, PM853_LDO4_EN_MSK,		\
			PM853_LDO4_SVSEL_REG, PM853_LDO_SVSEL_MSK,		\
			pm853_ldo_ranges1),					\
	\
	PM8XX_DESC_COMMON(PM853_ID_LDO5, "LDO_REG5",					\
			4, PM853_LDO5_VSEL_REG, PM853_LDO_VSEL_MSK,		\
			PM853_LDO_BUCK_EN_REG1, PM853_LDO5_EN_MSK,		\
			PM853_LDO5_SVSEL_REG, PM853_LDO_SVSEL_MSK,		\
			pm853_ldo_ranges2),					\
	\
	PM8XX_DESC_COMMON(PM853_ID_LDO6, "LDO_REG6",			\
			16, PM853_LDO6_VSEL_REG, PM853_LDO_VSEL_MSK,		\
			PM853_LDO_BUCK_EN_REG1, PM853_LDO6_EN_MSK,		\
			PM853_LDO6_SVSEL_REG, PM853_LDO_SVSEL_MSK,		\
			pm853_ldo_ranges1),					\
	\
	PM8XX_DESC_COMMON(PM853_ID_LDO7, "LDO_REG7",			\
			16, PM853_LDO7_VSEL_REG, PM853_LDO_VSEL_MSK,		\
			PM853_LDO_BUCK_EN_REG1, PM853_LDO7_EN_MSK,		\
			PM853_LDO7_SVSEL_REG, PM853_LDO_SVSEL_MSK,		\
			pm853_ldo_ranges3),					\
	\
	PM8XX_DESC_COMMON(PM853_ID_LDO8, "LDO_REG8",			\
			16, PM853_LDO8_VSEL_REG, PM853_LDO_VSEL_MSK,		\
			PM853_LDO_BUCK_EN_REG1, PM853_LDO8_EN_MSK,		\
			PM853_LDO8_SVSEL_REG, PM853_LDO_SVSEL_MSK,		\
			pm853_ldo_ranges1),					\
	\
	PM8XX_DESC_COMMON(PM853_ID_LDO9, "LDO_REG9",			\
			16, PM853_LDO9_VSEL_REG, PM853_LDO_VSEL_MSK,		\
			PM853_LDO_BUCK_EN_REG1, PM853_LDO9_EN_MSK,		\
			PM853_LDO9_SVSEL_REG, PM853_LDO_SVSEL_MSK,		\
			pm853_ldo_ranges1),					\
	\
	PM8XX_DESC_COMMON(PM853_ID_LDO10, "LDO_REG10",			\
			16, PM853_LDO10_VSEL_REG, PM853_LDO_VSEL_MSK,		\
			PM853_LDO_BUCK_EN_REG1, PM853_LDO10_EN_MSK,		\
			PM853_LDO10_SVSEL_REG, PM853_LDO_SVSEL_MSK,		\
			pm853_ldo_ranges1),					\
	\
	PM8XX_DESC_COMMON(PM853_ID_LDO11, "LDO_REG11",			\
			16, PM853_LDO11_VSEL_REG, PM853_LDO_VSEL_MSK,		\
			PM853_LDO_BUCK_EN_REG1, PM853_LDO11_EN_MSK,		\
			PM853_LDO11_SVSEL_REG, PM853_LDO_SVSEL_MSK,		\
			pm853_ldo_ranges3),					\
	\
	PM8XX_DESC_COMMON(PM853_ID_LDO12, "LDO_REG12",			\
			16, PM853_LDO12_VSEL_REG, PM853_LDO_VSEL_MSK,		\
			PM853_LDO_BUCK_EN_REG2, PM853_LDO12_EN_MSK,		\
			PM853_LDO12_SVSEL_REG, PM853_LDO_SVSEL_MSK,		\
			pm853_ldo_ranges1),					\
	\
	PM8XX_DESC_COMMON(PM853_ID_LDO13, "LDO_REG13",			\
			16, PM853_LDO13_VSEL_REG, PM853_LDO_VSEL_MSK,		\
			PM853_LDO_BUCK_EN_REG2, PM853_LDO13_EN_MSK,		\
			PM853_LDO13_SVSEL_REG, PM853_LDO_SVSEL_MSK,		\
			pm853_ldo_ranges1),					\
	\
	PM8XX_DESC_COMMON(PM853_ID_LDO14, "LDO_REG14",			\
			16, PM853_LDO14_VSEL_REG, PM853_LDO_VSEL_MSK,		\
			PM853_LDO_BUCK_EN_REG2, PM853_LDO14_EN_MSK,		\
			PM853_LDO14_SVSEL_REG, PM853_LDO_SVSEL_MSK,		\
			pm853_ldo_ranges1),					\
	\
	PM8XX_DESC_COMMON(PM853_ID_LDO15, "LDO_REG15",			\
			16, PM853_LDO15_VSEL_REG, PM853_LDO_VSEL_MSK,		\
			PM853_LDO_BUCK_EN_REG2, PM853_LDO15_EN_MSK,		\
			PM853_LDO15_SVSEL_REG, PM853_LDO_SVSEL_MSK,		\
			pm853_ldo_ranges3),					\
	\
	PM8XX_DESC_COMMON(PM853_ID_LDO16, "LDO_REG16",			\
			16, PM853_LDO16_VSEL_REG, PM853_LDO_VSEL_MSK,		\
			PM853_LDO_BUCK_EN_REG2, PM853_LDO16_EN_MSK,		\
			PM853_LDO16_SVSEL_REG, PM853_LDO_SVSEL_MSK,		\
			pm853_ldo_ranges1),					\
	\
	PM8XX_DESC_COMMON(PM853_ID_LDO17, "LDO_REG17",			\
			8, PM853_LDO17_VSEL_REG, PM853_LDO_VSEL_MSK,		\
			PM853_LDO_BUCK_EN_REG2, PM853_LDO17_EN_MSK,		\
			PM853_LDO17_SVSEL_REG, PM853_LDO_SVSEL_MSK,		\
			pm853_ldo_ranges4),					\
	\
	PM8XX_DESC_COMMON(PM853_ID_LDO18, "LDO_REG18",			\
			16, PM853_LDO18_VSEL_REG, PM853_LDO_VSEL_MSK,		\
			PM853_LDO_BUCK_EN_REG2, PM853_LDO18_EN_MSK,		\
			PM853_LDO18_SVSEL_REG, PM853_LDO_SVSEL_MSK,		\
			pm853_ldo_ranges3),					\
	\
	PM8XX_DESC_COMMON(PM853_ID_LDO19, "LDO_REG19",			\
			8, PM853_LDO19_VSEL_REG, PM853_LDO_VSEL_MSK,		\
			PM853_LDO_BUCK_EN_REG2, PM853_LDO19_EN_MSK,		\
			PM853_LDO19_SVSEL_REG, PM853_LDO_SVSEL_MSK,		\
			pm853_ldo_ranges4),					\
	\
	PM8XX_DESC_COMMON(PM853_ID_LDO20, "LDO_REG20",			\
			8, PM853_LDO20_VSEL_REG, PM853_LDO_VSEL_MSK,		\
			PM853_LDO_BUCK_EN_REG3, PM853_LDO20_EN_MSK,		\
			PM853_LDO20_SVSEL_REG, PM853_LDO_SVSEL_MSK,		\
			pm853_ldo_ranges4),					\
	\
	PM8XX_DESC_COMMON(PM853_ID_LDO21, "LDO_REG21",			\
			16, PM853_LDO21_VSEL_REG, PM853_LDO_VSEL_MSK,		\
			PM853_LDO_BUCK_EN_REG3, PM853_LDO21_EN_MSK,		\
			PM853_LDO21_SVSEL_REG, PM853_LDO_SVSEL_MSK,		\
			pm853_ldo_ranges3),					\
	\
	PM8XX_DESC_COMMON(PM853_ID_LDO22, "LDO_REG22",			\
			8, PM853_LDO22_VSEL_REG, PM853_LDO_VSEL_MSK,		\
			PM853_LDO_BUCK_EN_REG3, PM853_LDO22_EN_MSK,		\
			PM853_LDO22_SVSEL_REG, PM853_LDO_SVSEL_MSK,		\
			pm853_ldo_ranges4),					\
};

#define PM853_REGULATOR_SWITCH_DESC		\
static const struct pm8xx_buck_desc pm853_switch_desc[] = {	\
	PM8XX_DESC_COMMON(PM853_ID_SWITCH1, "SWITCH_REG1", 0, PM853_LDO_BUCK_EN_REG3, PM853_SW_EN_MSK,	\
			0, 0, 0, 0, pm853_switch_ranges),		\
};

#define PM853_REGULATOR_MATCH_DATA					\
struct regulator_match_data pm853_regulator_match_data = {		\
	.nr_buck_desc = ARRAY_SIZE(pm853_buck_desc),				\
	.buck_desc = pm853_buck_desc,						\
	.nr_ldo_desc = ARRAY_SIZE(pm853_ldo_desc),				\
	.ldo_desc = pm853_ldo_desc,						\
	.nr_switch_desc = ARRAY_SIZE(pm853_switch_desc),			\
	.switch_desc = pm853_switch_desc,					\
	.name = "pm853",							\
	.max_registers = 0xf1,							\
};

#define DECLEAR_PM853_REGULATOR_MATCH_DATA	extern struct regulator_match_data pm853_regulator_match_data;

#endif /* __SPACEMIT_PM853_H__ */
